<template>
	<view class="wrap">
		<u-navbar :title="$t('xgdlmm')" title-width="340" :border-bottom="false" back-icon-color="#fff" title-color="#fff" :background="{ backgroundColor: '#0030A8' }"></u-navbar>
		<view class="tom-container">
			<view class="list">
				<view class="row">
					<view class="row-label">{{$t('jmm')}}</view>
					<view class="row-main">
						<input type="password" v-model="Password" maxlength="20" v-if="!switch3" :placeholder="$t('qsrjmm')"
							placeholder-class="place-class" @blur="VerifyPassword" />
						<input type="text" v-model="Password" maxlength="20" v-else :placeholder="$t('qsrjmm')"
							placeholder-class="place-class" @blur="VerifyPassword" />
						<u-icon @click="switch3=!switch3" name="yanjing" :color="switch3?'#0030A8':'#999999'" size="36" custom-prefix="custom-icon"></u-icon>
					</view>
				</view>
				<view class="row">
					<view class="row-label">{{$t('xmm')}}</view>
					<view class="row-main">
						<input type="password" v-model="newPassword" maxlength="20" v-if="!switch1" :placeholder="$t('qsrxmm2')"
							placeholder-class="place-class" @blur="VerifyPassword2" />
						<input type="text" v-model="newPassword" maxlength="20" v-else :placeholder="$t('qsrxmm2')"
							placeholder-class="place-class" @blur="VerifyPassword2" />
						<u-icon @click="switch1=!switch1" name="yanjing" :color="switch1?'#0030A8':'#999999'" size="36" custom-prefix="custom-icon"></u-icon>
					</view>
				</view>
				<view class="row">
					<view class="row-label">{{$t('qrxmm')}}</view>
					<view class="row-main">
						<input type="password" v-model="confirmPassword" maxlength="20" v-if="!switch2" :placeholder="$t('qsrxmm2')"
							placeholder-class="place-class" @blur="VerifyPassword3" />
						<input type="text" v-model="confirmPassword" maxlength="20" v-else :placeholder="$t('qsrxmm2')"
							placeholder-class="place-class" @blur="VerifyPassword3" />
						<u-icon @click="switch2=!switch2" name="yanjing" :color="switch2?'#0030A8':'#999999'" size="36" custom-prefix="custom-icon"></u-icon>
					</view>
				</view>
				<view class="row" style="text-align: right;">
					<navigator url="/pages/User/Personal/AccessCode/details/details" style="color:#0032B7;font-size: 24rpx;display: inline-block;" hover-class="none">{{$t('wjmm')}}</navigator>
				</view>
				<view class="login_btn" @tap="submit">{{$t('qrxg')}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Password: '', // 旧密码
				newPassword: '', // 新密码
				confirmPassword: '', //确认新密码
				numberType: 0,
				/*账号类型，1手机2邮箱*/
				switch1: false,
				switch2: false,
				switch3: false,
			}
		},
		methods: {
			VerifyPassword() {
				if (this.$u.test.isEmpty(this.Password)) return this.$utils.toast(this.$t('qsrjmm'));
			},
			VerifyPassword2() {
				if (this.$u.test.isEmpty(this.newPassword)) return this.$utils.toast(this.$t('qsrxmm2'));
			},
			VerifyPassword3() {
				if (this.newPassword.toUpperCase() != this.confirmPassword.toUpperCase()) return this.$utils.toast(
					this.$t('lxsrbyz'));
			},
			// 确定-回调
			submit() {
				let reg = new RegExp('^(?![0-9A-Z]+$)(?![0-9a-z]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$');
				if (this.$u.test.isEmpty(this.Password)) return this.$utils.toast(this.$t('qsrjmm'));
				if (this.$u.test.isEmpty(this.newPassword)) return this.$utils.toast(this.$t('qsrxmm2'));
				if(!reg.test(this.Password)) return this.$utils.toast(this.$t('mimazh'));
				if(!reg.test(this.newPassword)) return this.$utils.toast(this.$t('mimazh'));
				if (this.newPassword.toUpperCase() != this.confirmPassword.toUpperCase()) return this.$utils.toast(this.$t('lxsrbyz'));
				this.$utils.loading(this.$t('qsh'))
				this.$api.loginApi.updatePassword({
						oldPassword: this.Password,
						newPassword: this.newPassword
					})
					.then(res => {
						this.$utils.toast(res.data)
						setTimeout(function(){
							uni.navigateBack()
						},1200)
					})
			},
		}
	}
</script>

<style lang="scss" scoped>
.tom-container {
	padding-top: 50rpx;
}
.list {
	flex: 1;
	display: flex;
	flex-direction: column;
	border-radius: 50rpx 50rpx 0rpx 0rpx;
	overflow: hidden;
	background-color: #fff;
	background-image: url('/static/new_images/showPopup.png');
	background-position: left bottom;
	background-repeat: no-repeat;
	background-size: 100% 800rpx;
	.row {
		margin: 30rpx;
	
		&:first-child {
			margin-top: 40rpx;
		}
	
		&-label {
			color: $tom-text-color;
			font-size: 28rpx;
			font-weight: bold;
		}
	
		&-main {
			margin-top: 28rpx;
			background-color: #FAFAFA;
			height: 68rpx;
			padding: 0 20rpx;
			display: flex;
			align-items: center;
	
			.place-class {
				color: #CCCCCC;
			}
	
			input {
				flex: 1;
				color: $tom-text-color;
				font-size: 24rpx;
			}
	
			&-tip {
				margin-left: 20rpx;
				color: $tom-text-color;
				font-size: 24rpx;
			}
		}
	}
}
</style>
